/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package sysmodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import sysmodel.Association;
import sysmodel.Component;
import sysmodel.DataType;
import sysmodel.GeneratorModel;
import sysmodel.SysmodelPackage;
import sysmodel.SystemModel;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>System Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link sysmodel.impl.SystemModelImpl#getComponents <em>Components</em>}</li>
 *   <li>{@link sysmodel.impl.SystemModelImpl#getTypes <em>Types</em>}</li>
 *   <li>{@link sysmodel.impl.SystemModelImpl#getAssociations <em>Associations</em>}</li>
 *   <li>{@link sysmodel.impl.SystemModelImpl#getExceptions <em>Exceptions</em>}</li>
 *   <li>{@link sysmodel.impl.SystemModelImpl#getGeneratorModel <em>Generator Model</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SystemModelImpl extends EObjectImpl implements SystemModel {
	/**
	 * The cached value of the '{@link #getComponents() <em>Components</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getComponents()
	 * @generated
	 * @ordered
	 */
	protected EList<Component> components;

	/**
	 * The cached value of the '{@link #getTypes() <em>Types</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypes()
	 * @generated
	 * @ordered
	 */
	protected EList<DataType> types;

	/**
	 * The cached value of the '{@link #getAssociations() <em>Associations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAssociations()
	 * @generated
	 * @ordered
	 */
	protected EList<Association> associations;

	/**
	 * The cached value of the '{@link #getExceptions() <em>Exceptions</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExceptions()
	 * @generated
	 * @ordered
	 */
	protected EList<sysmodel.Exception> exceptions;

	/**
	 * The cached value of the '{@link #getGeneratorModel() <em>Generator Model</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGeneratorModel()
	 * @generated
	 * @ordered
	 */
	protected GeneratorModel generatorModel;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SystemModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SysmodelPackage.Literals.SYSTEM_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Component> getComponents() {
		if (components == null) {
			components = new EObjectContainmentEList<Component>(Component.class, this, SysmodelPackage.SYSTEM_MODEL__COMPONENTS);
		}
		return components;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DataType> getTypes() {
		if (types == null) {
			types = new EObjectContainmentEList<DataType>(DataType.class, this, SysmodelPackage.SYSTEM_MODEL__TYPES);
		}
		return types;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Association> getAssociations() {
		if (associations == null) {
			associations = new EObjectContainmentEList<Association>(Association.class, this, SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS);
		}
		return associations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<sysmodel.Exception> getExceptions() {
		if (exceptions == null) {
			exceptions = new EObjectContainmentEList<sysmodel.Exception>(sysmodel.Exception.class, this, SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS);
		}
		return exceptions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public GeneratorModel getGeneratorModel() {
		return generatorModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetGeneratorModel(GeneratorModel newGeneratorModel, NotificationChain msgs) {
		GeneratorModel oldGeneratorModel = generatorModel;
		generatorModel = newGeneratorModel;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL, oldGeneratorModel, newGeneratorModel);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGeneratorModel(GeneratorModel newGeneratorModel) {
		if (newGeneratorModel != generatorModel) {
			NotificationChain msgs = null;
			if (generatorModel != null)
				msgs = ((InternalEObject)generatorModel).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL, null, msgs);
			if (newGeneratorModel != null)
				msgs = ((InternalEObject)newGeneratorModel).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL, null, msgs);
			msgs = basicSetGeneratorModel(newGeneratorModel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL, newGeneratorModel, newGeneratorModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SysmodelPackage.SYSTEM_MODEL__COMPONENTS:
				return ((InternalEList<?>)getComponents()).basicRemove(otherEnd, msgs);
			case SysmodelPackage.SYSTEM_MODEL__TYPES:
				return ((InternalEList<?>)getTypes()).basicRemove(otherEnd, msgs);
			case SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS:
				return ((InternalEList<?>)getAssociations()).basicRemove(otherEnd, msgs);
			case SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS:
				return ((InternalEList<?>)getExceptions()).basicRemove(otherEnd, msgs);
			case SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL:
				return basicSetGeneratorModel(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SysmodelPackage.SYSTEM_MODEL__COMPONENTS:
				return getComponents();
			case SysmodelPackage.SYSTEM_MODEL__TYPES:
				return getTypes();
			case SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS:
				return getAssociations();
			case SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS:
				return getExceptions();
			case SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL:
				return getGeneratorModel();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SysmodelPackage.SYSTEM_MODEL__COMPONENTS:
				getComponents().clear();
				getComponents().addAll((Collection<? extends Component>)newValue);
				return;
			case SysmodelPackage.SYSTEM_MODEL__TYPES:
				getTypes().clear();
				getTypes().addAll((Collection<? extends DataType>)newValue);
				return;
			case SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS:
				getAssociations().clear();
				getAssociations().addAll((Collection<? extends Association>)newValue);
				return;
			case SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS:
				getExceptions().clear();
				getExceptions().addAll((Collection<? extends sysmodel.Exception>)newValue);
				return;
			case SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL:
				setGeneratorModel((GeneratorModel)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SysmodelPackage.SYSTEM_MODEL__COMPONENTS:
				getComponents().clear();
				return;
			case SysmodelPackage.SYSTEM_MODEL__TYPES:
				getTypes().clear();
				return;
			case SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS:
				getAssociations().clear();
				return;
			case SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS:
				getExceptions().clear();
				return;
			case SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL:
				setGeneratorModel((GeneratorModel)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SysmodelPackage.SYSTEM_MODEL__COMPONENTS:
				return components != null && !components.isEmpty();
			case SysmodelPackage.SYSTEM_MODEL__TYPES:
				return types != null && !types.isEmpty();
			case SysmodelPackage.SYSTEM_MODEL__ASSOCIATIONS:
				return associations != null && !associations.isEmpty();
			case SysmodelPackage.SYSTEM_MODEL__EXCEPTIONS:
				return exceptions != null && !exceptions.isEmpty();
			case SysmodelPackage.SYSTEM_MODEL__GENERATOR_MODEL:
				return generatorModel != null;
		}
		return super.eIsSet(featureID);
	}

} //SystemModelImpl
